<?php get_instance()->view('common/header');?>
<style>
<!--
.webuploader-pick {
    position: relative;
    display: inline-block;
    cursor: pointer;
    background: #00b7ee;
    padding: 5px 15px;
    color: #fff;
    text-align: center;
    border-radius: 3px;
    overflow: hidden;
}
-->
</style>
<div class="page-container home">
  <?php get_instance()->view('common/sidebar');?>
  <div class="page-content-wrapper">
	  <div class="page-content">
	    <div class="row">
	      <div class="col-md-12">
	        <!-- BEGIN PAGE TITLE & BREADCRUMB-->
	        <h3 class="page-title"> 配送员列表 </h3>
	        <ul class="page-breadcrumb breadcrumb">
	          <li class="btn-group"> <a class="btn default ml_5 return" href="<?php echo getUrl('home');?>"><i class="fa fa-chevron-left"></i> 返回</a> </li>
	          <li> <i class="fa fa-home"></i> <a href="<?php echo getUrl('home');?>"> 首页  <i class="fa fa-angle-right"></i> </a></li>
	          <li><a href="javascript:void(0);">配送员列表</a></li>
	        </ul>
	        <!-- END PAGE TITLE & BREADCRUMB-->
	      </div>
	    </div>
	    <div class="row">
	      <div class="col-md-12">
	      	<div class="well">
					<form>
	                    <div class="form-body">
	                    	<div class="row">
		                    	<div class="col-md-6">
			                     	<div class="form-group">
		                                <label class="control-label col-md-2">注册时间： </label>
		                                <div class="col-md-10">
		                                   <div class="input-group">
		                                   		<input dp class="form-control form-filter" placeholder="开始时间" type="text" name="date_from">
												<span class="input-group-addon">
													到
												</span>
												<input dp class="form-control form-filter" placeholder="结束时间" type="text" name="date_to">
											</div>
		                                </div>
		                           </div> 
	                           </div>  
	                           <div class="col-md-6">
			                     	<div class="form-group">
		                                <label class="control-label col-md-2">状态： </label>
		                                <div class="col-md-10">
		                                   <select class="form-control form-filter" name="status">
		                                   	   <option value="">所有</option>
		                                   	   <?php foreach ($status as $k => $v):?>
		                                   	   <option value="<?php echo $k;?>"><?php echo $v;?></option>
		                                   	   <?php endforeach;?>
		                                   </select> 
		                                </div>
		                           </div> 
	                           </div>  
                           </div>        
	                    	<div class="row" style="margin-top: 10px;">
		                    	<div class="col-md-6">
			                     	<div class="form-group">
		                                <label class="control-label col-md-2">姓名： </label>
		                                <div class="col-md-10">
		                                   <input class="form-control form-filter" name="name" type="text" placeholder="姓名/手机号码">
		                                </div>
		                           </div> 
	                           </div>  
	                           <div class="col-md-6">
			                     	<div class="form-group">
			                     	<?php $workeStatus = (int)get('worke_status');?>
		                                <label class="control-label col-md-2">工作状态： </label>
		                                <div class="col-md-10">
		                                	 <select name="work_status" class="form-control form-filter">
												<option value="">所有</option>
												<option <?php if($workeStatus == 2):?>selected="selected"<?php endif;?> value="2">开工</option>
												<option <?php if($workeStatus == 1):?>selected="selected"<?php endif;?> value="1">未开工</option>
											</select>
		                                </div>
		                           </div> 
	                           </div>  
                           </div>        
	                    	<div class="row" style="margin-top: 10px;">
		                    	<div class="col-md-6">
			                     	<div class="form-group">
		                                <label class="control-label col-md-2">类型： </label>
		                                <div class="col-md-10">
		                                   <select name="type" class="form-control form-filter">
												<option value="" selected="selected">所有</option>
												<?php foreach ($type as $k => $v):?>
												<option value="<?php echo $k;?>"><?php echo $v;?></option>
												<?php endforeach;?>
											</select>
		                                </div>
		                           </div> 
	                           </div>  
	                           <div class="col-md-6">
			                     	<div class="form-group">
		                                <label class="control-label col-md-2">评分： </label>
		                                <div class="col-md-10">
		                                	 <select name="score" class="form-control form-filter">
												<option value="" selected="selected">所有</option>
												<option value="1">1</option>
												<option value="2">2</option>
												<option value="3">3</option>
												<option value="4">4</option>
												<option value="5">5</option>
											</select>
		                                </div>
		                           </div> 
	                           </div>  
                           </div>        
	                    	<div class="row" style="margin-top: 10px;">
		                    	<div class="col-md-12">
			                     	<div class="form-group location">
		                                <label style="width: 8.17666667%;" class="control-label col-md-2">区域： </label>
		                                <div class="col-md-3">
		                                   <select class="form-control province form-filter" placeholder="省份" name="province">
		                                   	   <option value=""></option>
		                                   	   <?php foreach ($province as $v):?>
		                                   	   <option value="<?php echo $v['id'];?>"><?php echo $v['name'];?></option>
		                                   	   <?php endforeach;?>
		                                   </select>
		                                </div>
		                                <div class="col-md-3">
		                                   <select class="form-control city form-filter" placeholder="城市" name="city">
		                                     <option value=""></option>
		                                   </select>
		                                </div>
		                                <div class="col-md-3">
		                                   <select class="form-control form-filter county" name="county[]" placeholder="区县" multiple></select>
		                                </div>
		                           </div> 
	                           </div> 
	                           <script type="text/javascript">
	                           		$(function(){
	                           			localtion.init({boxId:".location",url:"<?php echo getUrl('deliveryman/member/getAreaByPid');?>"});	
	                           			$('select').select2({allowClear:true});
		                           	});
	                           </script> 
                           </div>
                           <div class="row" style="margin-top: 10px;">
                           		<div class="col-md-6">
			                     	<div class="form-group">
			                     		<label class="control-label col-md-2"> </label>
		                           		<div class="col-md-6">
			                                   <button type="button" class="btn btn-default seach-btn"><i class="fa fa-search"></i> 搜索</button>
			                                   <script type="text/javascript">
													$(function(){
														$('.seach-btn').click(function(){
															$('#datatable').dataTable().fnDraw(true);
														});
													});
			                                   </script>
		                                </div>
                                	</div>
                                </div>
                           </div>     
	                    </div>	
                    </form>			 
				</div>
	      		<div class="portlet">
	            <div class="portlet-body">
	              <div class="table-container">
	                <div class="table-actions-wrapper"> <span> </span>
	                	<?php if (adminAuthority('member-add', 'deliveryman')):?>
	                  	<a class="btn btn-sm blue add-btn" href="javascript:void(0);"><i class="fa fa-plus"></i> 新增</a>
	                  	<?php endif;?>
                    </div>
	                <table class="table table-bordered table-hover scoll-title" id="datatable">
	                  <thead>
	                    <tr role="row" class="heading">
	                      <th width="120px">注册时间</th>
	                      <th width="">姓名</th>
						  <th width="">区域</th>
						  <th width="">手机</th>
						  <th width="100px">类型</th>
	                      <th width="100px">评分</th>
	                      <th width="100px">余额</th>
	                      <th width="100px">配送中</th>
	                      <th width="100px">接单</th>
	                      <th width="100px">完成</th>
	                      <th width="100px">完成超时</th>
	                      <th width="100px">状态</th>
	                      <th width="100px">操作</th>
	                    </tr>
	                  </thead>
	                  <tbody>
	                  </tbody>
	                </table>
	              </div>
	            </div>
	          </div>
	      </div>
	    </div>
	  </div>
  </div>
</div>
<div id="auth-modal" class="modal fade modal_small" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
        <h4 class="modal-title"></h4>
      </div>
      <form action="<?php echo getUrl('deliveryman/member/auth'); ?>" class="form-horizontal" id="auth-form" method="post">
        <div class="modal-body">
            <div class="form-group">
                <label class="control-label col-md-3">姓名</label>
                <div class="col-md-9 text name">
                  	李海平  
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3">身份证号码</label>
                <div class="col-md-9 text code">
                    500236199009102879
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3">身份证照片</label>
                <div class="col-md-9 img">
                	
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3">生活照</label>
                <div class="col-md-9 protrait">

                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3">审核</label>
                <div class="col-md-9">
                	<div class="radio-list">
						<label class="radio-inline"><input name="status" value="1" checked type="radio">通过</label>
						<label class="radio-inline"><input name="status" value="2" type="radio">拒绝</label>
					</div>
                </div>
            </div>
            <div class="form-group hide remarks-box">
                <label class="control-label col-md-3">拒绝原因 <span class="required">*</span></label>
                <div class="col-md-9">
                	<textarea rows="" cols="" class="form-control required" name="remarks"></textarea>
                </div>
            </div>
            <script type="text/javascript">
				$(function(){
					$('[name="status"]').change(function(){
						var v = $(this).val();
						if($(this).attr("checked") && v == 2){
							$('.remarks-box').removeClass('hide');
						}else{
							$('.remarks-box').addClass('hide');
						}
					});
				});
            </script>
        </div>
        <div class="modal-footer">
          <input type="hidden" name="id" value=""/>
          <button class="btn default" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i> 关闭</button>
          <button type="submit" class="btn green field-submit-btn"><i class="fa fa-save"></i> 保存</button>
          <script type="text/javascript">
          	$(function(){
              	
				var model = $('#auth-modal');
				$('.auth-btn').live('click', function(){
					var url = $(this).attr('href');
					l_blockUI();
		            $.ajax(url, {
		                dataType: 'json',
		                type: 'get',
		                success:function(data){

		                	if(data.status <= 0){
		                		show_message(data);
		                		return;
			                }

			                model.find('.name').html(data.data.name);
			                model.find('.code').html(data.data.identity_card);
			                model.find('.img').html('<img style="width:100%;" src="'+data.data.identity_card_img+'">');
			                model.find('.protrait').html('<img style="width:100%;" src="'+data.data.portrait+'">');
			                model.find('[name="status"]').attr('checked', false);
			                model.find('[name="status"][value="1"]').attr('checked', true);
			                model.find('[name="status"]').uniform();
			                model.find('[name="remarks"]').val('');
			                model.find('[name="id"]').val(data.data.id);
			                model.find('.remarks-box').addClass('hide');
							model.modal();
							App.unblockUI();
			            },
		                error: function () {
		                    show_message({status: 0, message: '请求超时'});
		                    App.unblockUI();
		                },
		                timeout: 60000
		            });
					return false;
				});	

				$.e_validate.init('#auth-form',{modal:model});
            });
          </script>
        </div>
      </form>
    </div>
  </div>
</div>
<div id="save-modal" class="modal fade modal_small" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
        <h4 class="modal-title"></h4>
      </div>
      <form action="<?php echo getUrl('deliveryman/member/save'); ?>" class="form-horizontal" id="save-form" method="post">
        <div class="modal-body">
            <div class="form-group">
                <label class="control-label col-md-3">姓名 <span class="required">*</span></label>
                <div class="col-md-9">
                  	<input name="name" class="form-control required" type="text" maxlength="6"/>  
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3">会员类型<span class="required">*</span></label>
                <div class="col-md-9">
                    <div class="radio-list">
						<label class="radio-inline"><input name="type" value="2" checked type="radio">平台配送员</label>
						<label class="radio-inline"><input name="type" value="1" type="radio">普通配送员</label>
					</div>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3">头像<span class="required">*</span></label>
                <div class="col-md-9">
                	<img class="portrait" style="height:100px;" src="<?php echo base_url('static/img/no_img_100.jpg');?>">
                    <div id="uploader-demo" style="margin-top:10px;">
					    <!--用来存放item-->
					    <div id="fileList" class="uploader-list"></div>
					    <div id="filePicker">选择图片</div>
					</div>
					<input type="hidden" name="portrait" value="" class="required"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3">身份证号码 <span class="required">*</span></label>
                <div class="col-md-9">
                    <input name="identity_card" class="form-control required" type="text"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3">身份证照片 <span class="required">*</span></label>
                <div class="col-md-9 img">
                	<img class="identity_card_img" style="height:150px;" src="<?php echo base_url('static/img/no_img_100.jpg');?>">
                	<div id="uploader-demo" style="margin-top:10px;">
					    <!--用来存放item-->
					    <div id="fileList" class="uploader-list"></div>
					    <div id="filePicker1">选择图片</div>
					</div>
					<input type="hidden" name="identity_card_img" value="" class="required"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3">手机号码 <span class="required">*</span></label>
                <div class="col-md-9">
                	<input name="mobile" class="form-control required" type="text" mobile="true"/>
                	<span class="help-block">登录密码默认为手机号码的后6位</span>
                </div>
            </div>
            <div class="form-group" id="area">
               <label class="control-label col-md-3">区域<span class="required">*</span> </label>
               <div class="col-md-9">
	            	<div class="row area-row" style="margin-bottom:10px;" index="'+index+'">
                         <div class="col-md-4">
                              <select class="form-control province required" placeholder="省份" name="province">
                                <option value=""></option>
                                <?php foreach ($province as $v):?>
                                <option value="<?php echo $v['id'];?>"><?php echo $v['name'];?></option>
                                <?php endforeach;?>
                              </select>
                          </div>
                         <div class="col-md-4">
	                         <select class="form-control city required" placeholder="城市" name="city">
	                                <option value=""></option>
	                        </select>
                      	</div>
                    	<div class="col-md-4">
                        	<select class="form-control county required" placeholder="区县" name="county"></select>
                   		</div>
				   </div>	                   
               </div>
		    </div>
            <div class="form-group">
                <label class="control-label col-md-3">状态</label>
                <div class="col-md-9">
                	<div class="radio-list">
						<label class="radio-inline"><input name="status" value="2" checked type="radio">启用</label>
						<label class="radio-inline"><input name="status" value="1" type="radio">停用</label>
					</div>
                </div>
            </div>
        </div>
        <div class="modal-footer">
          <input type="hidden" name="id" value=""/>
          <button class="btn default" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i> 关闭</button>
          <button type="submit" class="btn green field-submit-btn"><i class="fa fa-save"></i> 保存</button>
          <script type="text/javascript">
          	$(function(){
              	
				var model = $('#save-modal');
				$('.add-btn').live('click', function(){
					model.find('.modal-title').html('新增');
					model.find('.has-error').removeClass('has-error').find('.validate_message').remove();
					model.find('.show_message_error').remove();
					model.find('input[type="text"],input[type="password"]').val('');
					model.find('input[name="status"]').attr('checked', false);
					model.find('input[name="status"][value="2"]').attr('checked', true);
					model.find('input[name="status"]').uniform();
					model.find('input[name="type"]').attr('checked', false);
					model.find('input[name="type"][value="2"]').attr('checked', true);
					model.find('input[name="type"]').uniform();
					model.find('.identity_card_img').val('<?php echo base_url('static/img/no_img_100.jpg');?>');
					model.find('.portrait').val('<?php echo base_url('static/img/no_img_100.jpg');?>');
					model.find('[name="portrait"],[name="identity_card_img"]').addClass('required');
					model.find('').uniform();
					model.find('select').val('').select2();
					localtion.init({boxId:'#area',url:"<?php echo getUrl('deliveryman/member/getAreaByPid');?>"});
					model.modal();
				});	

				var init = false;
				model.on('shown.bs.modal', function (e) {

					if( ! init){
						var uploader = WebUploader.create({
						    // 文件接收服务端。
						    server: '<?php echo getUrl('deliveryman/member/uploadImge');?>',
						    pick: '#filePicker',
						    resize: false,
						    auto: true,
						    fileVal:'Filedata',
						    duplicate:true,
						    accept: {
						        title: 'Images',
						        extensions: 'gif,jpg,jpeg,bmp,png',
						        mimeTypes: 'image/*'
						    }
						});

						uploader.on( 'uploadSuccess', function( file, response) {
                            $("[name='portrait']").val(response._raw);
                            $('.portrait').attr('src', response._raw);
                        });
						
						var uploader1 = WebUploader.create({
						    // 文件接收服务端。
						    server: '<?php echo getUrl('deliveryman/member/uploadImge');?>',
						    pick: '#filePicker1',
						    resize: false,
						    auto: true,
						    fileVal:'Filedata',
						    duplicate:true,
						    accept: {
						        title: 'Images',
						        extensions: 'gif,jpg,jpeg,bmp,png',
						        mimeTypes: 'image/*'
						    }
						});

						uploader1.on( 'uploadSuccess', function( file, response) {
                            $("[name='identity_card_img']").val(response._raw);
                            $('.identity_card_img').attr('src', response._raw);
                        });

						init = true;
					}
				});
				
				$('.edit-btn').live('click', function(){
					var url = $(this).attr('href');
					l_blockUI();
		            $.ajax(url, {
		                dataType: 'json',
		                type: 'get',
		                success:function(data){

		                	if(data.status <= 0){
		                		show_message(data);
		                		return;
			                }
		                	model.find('input[type="text"],input[type="hidden"]').val('');
			                model.find('[name="name"]').val(data.data.name);
			                model.find('[name="identity_card"]').val(data.data.identity_card);
			                model.find('.portrait').attr('src', data.data.portrait);
			                model.find('.identity_card_img').attr('src', data.data.identity_card_img);
			                model.find('[name="status"]').attr('checked', false);
			                if(data.data.status == 4){
				                model.find('[name="status"][value="1"]').attr('checked', true);
			                }else{
				                model.find('[name="status"][value="2"]').attr('checked', true);
				            }
			                model.find('[name="status"]').uniform();
			                model.find('[name="type"]').attr('checked', false);
				            model.find('[name="type"][value="'+data.data.type+'"]').attr('checked', true);
			                model.find('[name="type"]').uniform();

			                model.find('[name="mobile"]').val(data.data.mobile);
			                model.find('[name="portrait"],[name="identity_card_img"]').removeClass('required');
			                model.find('[name="id"]').val(data.data.id);
			                model.find('select').val('').select2();
							localtion.init({city:data.data.city_id,county:data.data.county_id,boxId:'#area',url:"<?php echo getUrl('deliveryman/member/getAreaByPid');?>"});
			                model.find('select.province').val(data.data.province_id).change();
							model.modal();
							App.unblockUI();
			            },
		                error: function () {
		                    show_message({status: 0, message: '请求超时'});
		                    App.unblockUI();
		                },
		                timeout: 60000
		            });
					return false;
				});	

				$.e_validate.init('#save-form',{modal:model,ignore:''});
            });
          </script>
        </div>
      </form>
    </div>
  </div>
</div>
<script type="text/javascript">
	$(function(){
		datatable_init({
			src: $("#datatable"),
			sAjaxSource: "<?php echo getUrl('deliveryman/member/getList');?>",
			aoColumnDefs : [{
                'bSortable' : false,
                'aTargets' : [ 0,1,2,3,4,5,7,10,11]
            }],
		});

        $('[dp]').not("[noinit]").datepicker({
            changeMonth: true,
            autoclose: true,
            format: "yyyy-mm-dd",
            language: 'zh-CN'
        });
	});
</script>
</body>
</html>